// pages/Home/home.js
import HomeApi from "../../utils/home/index"
var Tx = require('../../utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.js');
var qqmapsdk = new Tx({
  key: '4WXBZ-DUI63-DOZ3Z-YCCHU-TGLXO-IQB76' // 必填
});

Page({

  /**
   * 页面的初始数据
   */

  data: {
    soonlist:[],
    hotlist: [],
    selectlist:[],
    city: "",
    topH: wx.getMenuButtonBoundingClientRect().top + wx.getMenuButtonBoundingClientRect().height + "px",
    background: ['../../assets/images/icons/banner1.png', '../../assets/images/icons/banner2.png', '../../assets/images/icons/banner3.png'],
    indicatorDots: true,
    autoplay: false,
    interval: 2000,
    duration: 500,
 
  },
  gethotlist() {
  var  _this = this
    HomeApi.in_theaters().then((res) => {
    
      _this.setData({
        hotlist:res.data.data.list
      }) 
      
    })
  },

  getsoonlist(){
    var  _this = this
    HomeApi.coming_soon().then((res) => {
    
      _this.setData({
        soonlist:res.data.data.list
      }) 
      console.log(_this.soonlist);
    })
  },
  getselectlist(){
    var  _this = this
    HomeApi.selectPreview().then((res) => {
    console.log(res);
    
      _this.setData({

        selectlist:res.data.data
      }) 
    
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */



  onLoad: function (options) {

    this.gethotlist()
    this.getsoonlist()
    this.getselectlist()

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  getLocation() {
    var _this = this
    wx.getLocation({
      success(res) {

        qqmapsdk.reverseGeocoder({
          location: `${res.latitude},${res.longitude}`,
          success(val) {

            _this.setData({
              city: val.result.ad_info.city
            })
          }
        })
      }
    })
  },
  onShow: function () {
    this.getLocation()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})